package offline;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.Set;

import util.RedisCluster;
import util.RedisClusterFactory;
import db.RedisClientOVLP;

public class DumpSTLData {
	public static void main(String[] args) throws UnsupportedEncodingException,
			IOException {
		if (args.length < 1) {
			System.out.println("input id of the host to dump");
		}
		int nid = Integer.parseInt(args[0]);
		// int nid = 0;
		FileOutputStream fis = new FileOutputStream("./blgflw" + nid, true);

		try {
			RedisCluster folRedisCluster = RedisClusterFactory.instance
					.getFolRedisCluster();

			Set<String> uids = folRedisCluster.getJedis(nid).keys(
					"*" + RedisClientOVLP.SETOFBELONGEDTL);

			for (String uid : uids) {
				Set<String> sids = folRedisCluster.getJedis(nid).smembers(uid);// get
				for (String sid : sids) {
					fis.write(String.format("%s\t%s\n", uid, sid).getBytes(
							"utf-8"));
				}
			}
		} finally {
			fis.close();
		}
	}
}
